import { get } from 'lodash-es'

export class SysMenu {
  id?: string
  code?: number
  name?: string
  parent_code?: number
  parent_codes?: Array<number>
  redirect?: string
  path?: string
  component?: string
  hidden?: boolean
  alwaysShow?: boolean
  title?: string
  icon?: string
  noCache?: boolean
  breadcrumb?: boolean
  affix?: boolean
  noTagsView?: boolean
  activeMenu?: string
  followAuth?: string
  canTo?: boolean
  menu_type?: string
  permissions?: string
  disabled?: boolean
  sequence?: number
  created_id?: string
  updated_id?: string
  created_at?: string
  updated_at?: string
  version?: number;
  [key: string]: any

  constructor(data?: SysMenu) {
    this.init(data)
  }
}

SysMenu.prototype.init = function init(data?: SysMenu) {
  this.id = get(data, 'id')
  this.code = get(data, 'code')
  this.name = get(data, 'name', '')
  this.parent_code = get(data, 'parent_code')
  this.parent_codes = get(data, 'parent_codes')
  this.redirect = get(data, 'redirect')
  this.path = get(data, 'path')
  this.component = get(data, 'component')
  this.hidden = get(data, 'hidden', false)
  this.alwaysShow = get(data, 'alwaysShow', true)
  this.title = get(data, 'title')
  this.icon = get(data, 'icon')
  this.noCache = get(data, 'noCache', true)
  this.breadcrumb = get(data, 'breadcrumb', true)
  this.affix = get(data, 'affix', false)
  this.noTagsView = get(data, 'noTagsView', false)
  this.activeMenu = get(data, 'activeMenu')
  this.followAuth = get(data, 'followAuth')
  this.canTo = get(data, 'canTo', true)
  this.menu_type = get(data, 'menu_type', 'C')
  this.permissions = get(data, 'permissions')
  this.disabled = get(data, 'disabled', false)
  this.sequence = get(data, 'sequence', 1)
  this.created_id = get(data, 'created_id')
  this.updated_id = get(data, 'updated_id')
  this.created_at = get(data, 'created_at')
  this.updated_at = get(data, 'updated_id')
  this.version = get(data, 'version')
}
